import { BrowserWindow, ipcMain } from 'electron'
import registerTaskStoreIpc from './eStore/taskStore'
import registerBaseStoreIpc from './eStore/baseStore'
import registerFsIpc from './fsIpc'

// 程序相关
export default function registerAppIpc() {
  // 主进程处理渲染进程发送的消息
  ipcMain.on('window-minimize', () => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) window.minimize()
  })
  ipcMain.on('window-maximize', (event) => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) {
      if (window.isMaximized()) {
        window.unmaximize()
      } else {
        window.maximize()
      }
    }
    event.sender.send('window-state', window?.isMaximized() ? 'maximized' : 'restored')
  })
  ipcMain.on('window-close', () => {
    const window = BrowserWindow.getFocusedWindow()
    if (window) window.close()
  })

  registerTaskStoreIpc()
  registerBaseStoreIpc()
  registerFsIpc()
}
